<?php
require(__DIR__ . "/conn.php");
//tbl_board表：
//根据版块编号获取版块信息
/**
 * 根据版块编号获取版1块信息
 * @param int $boardid 板块编号
 * @return array
 */
function get_board($boardid)
{
    $sql = "SELECT * FROM tbl_topic WHERE boardid = $boardid";
    $result = exec_select($sql);
    if ($result) {
        return $result;
    } else {
        return array();
    }
}



//获取所有的版块信息
/**
 * 返回的信息分别是boardid，   boardName，   number
 * @return array
 */
function get_all_boards()
{
    $sql="select boardid,boardName,(select count(*) from tbl_topic where boardid=tbl_board.boardid) as number from tbl_board";
    $result=exec_select($sql);
    if($result){
        return $result;
    }else{
        return array();
    }
}
//添加板块
function add_board($boardName){
    $sql="insert into tbl_board(boardName) values('$boardName')";
    $result=exec_update($sql);
    if($result){
        return true;
    }else{
        return false;
    }
}
/**
 * 查询某个板块下的帖子数量
 * @param int $boardid
 * @return int
 */
function count_topics_by_board($boardid) {
    $sql = "SELECT COUNT(*) as num FROM tbl_topic WHERE boardid = $boardid";
    $result = exec_select($sql);
    return isset($result[0]['num']) ? intval($result[0]['num']) : 0;
}
?>